﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.Mvc;
using Model;
using Service;
namespace 企业门户.Areas.HT.Controllers
{
    public class HouTaiController : Controller
    {
        Model1 db = new Model1();
        ArticleService articleService = new ArticleService();

        //主页面
        // GET: HT/HouTai
        public ActionResult Index()
        {
            return View();
        }
        //首页
        public ActionResult main()
        {
            return View();
        }

        //layout3
        public ActionResult layout3()
        {
            return View();
        }

        //layout2
        public ActionResult layout2()
        {
            return View();
        }

        //用户管理
        [HttpGet]
        public new ActionResult User()
        {
            return View();
        }

        //用户列表分页数据源
        [HttpGet]
        public ActionResult UserData(int page, int rows, string uname, bool? admin)
        {
            var plist = articleService.Paging(page, rows, uname, admin);
            return Json(plist, JsonRequestBehavior.AllowGet);
        }

        //删除用户
        [HttpGet]
        public ActionResult Delete(int uid)
        {
            articleService.remove(uid);
            return View();
        }


        //添加用户
        [HttpGet]
        public ActionResult openAdd()
        {
            return View();
        }
        [HttpPost]
        public ActionResult openAdd(CMS_User u)
        {
            if (u.uname != null && u.upwd != null &&u.admin!=null)
            {
                articleService.Add(u);
                return View();
            }
            else
            {
                ViewBag.ErrorMessage = "请输入正确数据！";
                return View();
            }
            
        }


        //修改用户
        [HttpGet]
        public ActionResult openEdit(int id)
        {
            return View();
        }
        
        //加载用户内容，用于修改用户
        public ActionResult EditLoad(int id)
        {
            return Json(articleService.Find(id),JsonRequestBehavior.AllowGet);
        }

        //修改用户内容
        [HttpPost,ValidateInput(false)]
        public ActionResult openEdit(int id,string uname,string upwd,string nname,string mobile,string face,bool admin,CMS_User u)
        {
            
            u.uid = id;
            u.uname = uname;
            u.upwd = upwd;
            u.nname = nname;
            u.mobile = mobile;
            u.face = face;
            u.admin = admin;
            articleService.Update(u);
            return View();
        }

        //销毁
        protected override void Dispose(bool disposing)
        {
            db.Dispose();
            articleService.Dispose();
        }
    }
}